home *** CD-ROM | disk | FTP | other *** search
/ Complete Linux / Complete Linux.iso / docs / apps / database / ingres04.lzh / source / iutil / put_tuple.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-09-18  |  3.2 KB  |  193 lines

  1. # include    <ingres.h>
  2. # include    <symbol.h>
  3. # include    <access.h>
  4. # include    <catalog.h>
  5. # include    <sccs.h>
  6.  
  7. SCCSID(@(#)put_tuple.c    8.2    5/1/86)
  8.  
  9.  
  10.  
  11. char    *Acctuple;
  12. char    Accanon[MAXTUP];
  13.  
  14.  
  15. /*
  16. **  PUT_TUPLE
  17. **
  18. **    Put the canonical tuple in the position
  19. **    on the current page specified by tid
  20. **
  21. **    Trace Flags:
  22. **        27.3-5
  23. */
  24.  
  25. put_tuple(tid, tuple, length)
  26. TID    *tid;
  27. char    *tuple;
  28. int    length;
  29. {
  30.     register char    *tp, *ttp;
  31.     char        *get_addr();
  32.     register    i;
  33.  
  34. #    ifdef xATR2
  35.     if (tTf(27, 3))
  36.     {
  37.         printf("put_tuple:len=%d,", length);
  38.         ttp = tuple;
  39.         for (i = 0; i < length; i++)
  40.         {
  41.             printf("%3d,", *ttp);
  42.             ttp++;
  43.         }
  44.         dumptid(tid);
  45.     }
  46. #    endif
  47.  
  48.     /* get address in buffer */
  49.     tp = get_addr(tid);
  50.  
  51.     /* move the tuple */
  52.     bmove(tuple, tp, length);
  53.  
  54.     /* mark page as dirty */
  55.     Acc_head->bufstatus |= BUF_DIRTY;
  56. }
  57. /*
  58. **  CANONICAL
  59. **
  60. **    Make the tuple canonical and return the length
  61. **    of the tuple.
  62. **
  63. **    If the relation is compressed then the tuple in
  64. **    compressed into the global area Accanon.
  65. **
  66. **    As a side effect, the address of the tuple to be
  67. **    inserted is placed in Acctuple.
  68. **
  69. **    returns: length of canonical tuple
  70. **
  71. **    Trace Flags:
  72. **        27.6, 7
  73. */
  74.  
  75. canonical(d, tuple)
  76. register DESC    *d;
  77. register char    *tuple;
  78. {
  79.     register int    i;
  80.  
  81.     if (d->reldum.relspec < 0)
  82.     {
  83.         /* compress tuple */
  84.         i = comp_tup(d, tuple);
  85.         Acctuple = Accanon;
  86.     }
  87.     else
  88.     {
  89.         Acctuple = tuple;
  90.         /* ignore lid field */
  91.         i = d->reldum.relwid - 4 * d->reldum.reldim;
  92.     }
  93. #    ifdef xATR3
  94.     if (tTf(27, 6))
  95.         printf("canonical: %d\n", i);
  96. #    endif
  97.     return (i);
  98. }
  99. /*
  100. **  COMP_TUP
  101. **
  102. **    Compress the tuple into Accanon. Compression is
  103. **    done by copying INT and FLOAT as is.
  104. **    For CHAR fields, the tuple is copied until a null
  105. **    byte or until the end of the field. Then trailing
  106. **    blanks are removed and a null byte is inserted at
  107. **    the end if any trailing blanks were present.
  108. */
  109.  
  110. comp_tup(d, src)
  111. register DESC    *d;
  112. register char    *src;
  113. {
  114.     register char    *dst;
  115.     char        *save;
  116.     char        *domlen, *domtype;
  117.     int        i, j, len, numatts;
  118.  
  119.     dst = Accanon;
  120.  
  121.     domlen = &d->relfrml[1];
  122.     domtype = &d->relfrmt[1];
  123.     save = src - d->reloff[1];
  124.  
  125.     /* ignore lid field */
  126.     numatts = d->reldum.relatts - d->reldum.reldim;
  127.     for (i = 1; i <= numatts; i++)
  128.     {
  129.         len = *domlen++ & I1MASK;
  130.         src = save + d->reloff[i];
  131.         if (*domtype++ == CHAR)
  132.         {
  133.             for (j = 1; j <= len; j++)
  134.             {
  135.                 if ((*dst++ = *src++) == (char *)NULL)
  136.                 {
  137.                     dst--;
  138.                     break;
  139.                 }
  140.             }
  141.  
  142.             while (j--)
  143.                 if (*--dst != ' ')
  144.                     break;
  145.  
  146.             if (j != len)
  147.                 *++dst = (char *)NULL;
  148.  
  149.             dst++;
  150.         }
  151.         else
  152.         {
  153.             while (len--)
  154.                 *dst++ = *src++;
  155.  
  156.         }
  157.     }
  158.     return (dst - Accanon);
  159. }
  160. /*
  161. **  SPACE_LEFT
  162. **
  163. **    Determine how much space remains on the page in
  164. **    the current buffer. Included in computation
  165. **    is the room for an additional line number
  166. */
  167.  
  168. space_left(bp)
  169. register struct accbuf    *bp;
  170. {
  171.     register int    nextoff;
  172.     register int    i;
  173.     register short    *pp;
  174.  
  175.     nextoff = bp->nxtlino;
  176. #    ifdef xATR3
  177.     if (nextoff < 0 || nextoff > PGSIZE)
  178.         syserr("space_left: nextoff=%d", nextoff);
  179. #    endif
  180.  
  181.     /* compute space left on page */
  182.     pp = &bp->linetab[-nextoff];
  183.     i = PGSIZE - *pp - (nextoff + 2) * 2;
  184.  
  185.     /* see if there is also a free line number */
  186.     if (nextoff < MAXLINENO)
  187.         return (i);
  188.     while (++pp <= &bp->linetab[0])
  189.         if (*pp == 0)
  190.             return (i);
  191.     return (0);
  192. }
  193.